package com.blb.controller;

import com.blb.pojo.Score;
import com.blb.pojo.Student;
import com.blb.service.ScoreService;
import com.blb.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.jws.WebParam;
import java.util.List;

@Controller
public class ScoreController {

    @Autowired
    private ScoreService scoreService;

    @Autowired
    private StudentService studentService;

    @RequestMapping("/score/findAll")
    public String findAllScores(Model model){
        List<Score> scores = scoreService.getAll();
        model.addAttribute("scores",scores);
        return "scores";
    }

    @RequestMapping("/score/findById")
    public String findById(Long id,Model model){
        Score score = scoreService.getById(id);
        List<Student> students = studentService.list();
        model.addAttribute("score",score);
        model.addAttribute("students",students);
        return "update-score";
    }

    @RequestMapping("/score/doUpdate")
    public String doUpdate(Score score){
        scoreService.updateById(score);
        return "redirect:/score/findAll";
    }
}
